<?php
/**
 * Created by PhpStorm.
 * User: jason
 * Date: 2017/11/30
 * Time: 22:56
 */

namespace Home\Controller;


use Home\Service\SheetService;

class RankController extends HomeController
{
    public function __construct()
    {
        parent::__construct();
        $this->assign('nav', 'rank');
    }

    /**
     * 总榜排行
     */
    public function index()
    {
        $param = I('param.');
        $page = is_numeric($param['p']) ? $param['p'] : 1;
        $style = $param['style']&& in_array($param['style'], ['guitar', 'piano', 'zither']) ? $param['style'] : 'total';  //排行榜类型
        $sheetService = new SheetService();
        $map = array(
            'is_delete' => 0,
        );
        switch ($style) {
            case 'guitar':
                $map['name'] = ['like', '%吉他%'];
                break;
            case 'piano':
                $map['name'] = ['like', '%钢琴%'];
                break;
            case 'zither':
                $map['name'] = ['like', '%古筝%'];
                break;
        }
        $order = 'click_count desc';
        $list = $sheetService->topRank($map, $page, 10, $order, $count);
        $this->assign('sheetList', $list);
        //分页
        $Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出
        $this->assign('page',$show);// 赋值分页输出
        $this->display('Rank/'. $style);
    }
}